﻿<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="UsrManageSuscripciones.aspx.cs" Inherits="UsrManageSuscripciones" Title="Suscripciones" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <!--
    <link href="https://google-developers.appspot.com/maps/documentation/javascript/examples/default.css" rel="stylesheet" />
    -->

    <script src="https://maps.googleapis.com/maps/api/js?sensor=false" type="text/javascript"></script>

    <script type="text/javascript">
        var markers_info = [];
    </script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="body" runat="Server">
    <div class="t_cent">
        <asp:RadioButtonList ID="rbl_accion" runat="server" RepeatDirection="Horizontal"
            AutoPostBack="true" OnSelectedIndexChanged="rbl_accion_SelectedIndexChanged">
            <asp:ListItem Value="0" Text="Mis suscripciones"></asp:ListItem>
            <asp:ListItem Value="1" Text="Explorar"></asp:ListItem>
        </asp:RadioButtonList>
    </div>
    <asp:Panel ID="pnl_MisSuscripciones" runat="server" Visible="true" Style="margin-top: 20px;">
        <div style="max-width: 600px; margin: auto auto; padding-left: 10px; padding-right: 10px;">
            <span class="membrete">Filtrar</span>
            <input type="text" id="txt_filtro" />
            <span class="membrete">Suscripciones</span>
            <div style="margin-top: 10px;">
                <asp:Label ID="lbl_nosuscripciones" runat="server" CssClass="membretedato" Text="No tenés suscripciones asociadas"></asp:Label>
                <asp:DataGrid ID="dg_MisSuscripciones" runat="server" AutoGenerateColumns="false"
                    CssClass="grilla" Width="100%">
                    <Columns>
                        <asp:BoundColumn DataField="idempresa" Visible="false"></asp:BoundColumn>
                        <asp:BoundColumn DataField="idpublicacion" Visible="false"></asp:BoundColumn>
                        <asp:BoundColumn DataField="Logo" HeaderText="Logo" HeaderStyle-Width="50" DataFormatString="<img alt='Logo' src='{0}' style='width:50px;height:50px;'></img>">
                        </asp:BoundColumn>
                        <asp:BoundColumn DataField="Descripcion" HeaderText="Descripción"></asp:BoundColumn>
                        <asp:BoundColumn DataField="link" HeaderStyle-Width="40"></asp:BoundColumn>
                    </Columns>
                </asp:DataGrid>
            </div>
        </div>
    </asp:Panel>
    <asp:Panel ID="pnl_Explorar" runat="server" Visible="false" Style="margin-top: 20px;">
        <div class="tabs">
            <ul>
                <li><a href="#tabs-listado">Listado</a></li>
                <li><a href="#tabs-mapa" onclick="javascript:if(map!=null)return;setTimeout(function(){initialize();drop()},1000);">
                    Mapa Localizador</a></li>
            </ul>
            <div id="tabs-listado">
                <span class="membrete">Búsqueda</span>
                <asp:TextBox ID="txt_busqueda" runat="server" Width="60%"></asp:TextBox>
                <a id="advanced-search" onclick="javascript:toggleAdvancedSearch();">Busqueda Avanzada</a>
                <asp:Button ID="btn_buscar" runat="server" Text="Buscar" OnClick="btn_buscar_Click" />
                <div>
                    <fieldset id="advanced-search-content" class="membrete" style="margin-top: 20px;
                        padding-left: 40px; width: 400px; display: none;">
                        <legend>Búsqueda Avanzada</legend><span class="membrete">Razón Social</span>
                        <input id="t_razonsoc" type="text" />
                        <span class="membrete">Rubro</span>
                        <input id="t_rubro" type="text" />
                        <span class="membrete">Descripción</span>
                        <input id="t_desc" type="text" />
                        <span class="membrete">Número de Publicación</span>
                        <input id="t_nropub" type="text" />
                        <div style="text-align: right; padding-right: 20px;">
                            <asp:Button ID="btn_advanced_Search" runat="server" OnClick="btn_buscar_Click" Text="Buscar" />
                        </div>
                    </fieldset>
                </div>
                <span class="membrete">Resultado</span>
                <asp:Label ID="lbl_nobusqueda" runat="server" CssClass="membretedato" Text="No se encontró ningún resultado para su búsqueda"></asp:Label>
                <asp:DataGrid ID="dg_Exploracion" runat="server" AutoGenerateColumns="false" CssClass="grilla"
                    Width="80%">
                    <Columns>
                        <asp:BoundColumn DataField="idempresa" Visible="false"></asp:BoundColumn>
                        <asp:BoundColumn DataField="idpublicacion" Visible="false"></asp:BoundColumn>
                        <asp:BoundColumn DataField="Logo" HeaderText="Logo" HeaderStyle-Width="50" DataFormatString="<img alt='Logo' src='{0}' style='width:50px; height:50px;'></img>">
                        </asp:BoundColumn>
                        <asp:BoundColumn DataField="Descripcion" HeaderText="Descripción"></asp:BoundColumn>
                        <asp:BoundColumn DataField="link"></asp:BoundColumn>
                    </Columns>
                </asp:DataGrid>
            </div>
            <div id="tabs-mapa">
                <div id="map_canvas" style="width: 100%; height: 600px;">
                    <div class="t_cent">
                        <img src="static/loading.gif" alt="..." class="blk b_cent" /><span>Cargando mapa</span></div>
                </div>
            </div>
        </div>
    </asp:Panel>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" runat="Server">

    <script type="text/javascript">
	
	var latLongC = [-34.6106, -58.3853];	
	
	function getLocation(){
		if (navigator.geolocation) {
			// Get current position
			navigator.geolocation.getCurrentPosition(
				function (position) {
					// Success!
					latLongC = [position.coords.latitude, position.coords.longitude];
				},
				null,
				{timeout:2000}
			);
		}
	 }
	 getLocation();
	  
        /*
      var markers_info = [
        { title : "Prueba 1", info : "Prueba info 1", localization : new google.maps.LatLng(52.511467, 13.447179) },
        { title : "Prueba 2", info : "Prueba info 2", localization : new google.maps.LatLng(52.549061, 13.422975) },
        { title : "Prueba 3", info : "Prueba info 3", localization : new google.maps.LatLng(52.497622, 13.396110) },
        { title : "Prueba 4", info : "Prueba info 4", localization : new google.maps.LatLng(52.517683, 13.394393) }
      ];
        */
      var markers = [];
      var iterator = 0;
      var map = null;

      function initialize() {
            
        var mapOptions = {
          zoom: 12,
          mapTypeId: google.maps.MapTypeId.ROADMAP,
          center: new google.maps.LatLng(latLongC[0],latLongC[1])
        };

        map = new google.maps.Map(document.getElementById('map_canvas'),
                mapOptions);

      }

      function drop() {
        for (var i = 0; i < markers_info.length; i++) {
          setTimeout(function() {
            addMarker();
          }, i * 300);
        }
      }

      var infowindow = null;

      function addMarker() {
        var marker = new google.maps.Marker({
                              position: markers_info[iterator].localization,
                              map: map,
                              draggable: false,
                              animation: google.maps.Animation.DROP,
                              title: markers_info[iterator].title,
                              info: markers_info[iterator].info                              
                            })
        markers.push(marker);
        iterator++;
        
        google.maps.event.addListener(marker, 'click', function() {
          if(infowindow != null)
            infowindow.close();
            
          infowindow = new google.maps.InfoWindow({
                content: this.info,
                maxWidth: 350
            });
          
          infowindow.open(map,this);
          
        });
      }
      
              
    </script>

    <script type="text/javascript">
        $(document).ready(doBind);
        aspbh_endHandler.push(doBind);
        
        jQuery.expr[':'].contains = function(a,i,m){
             return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0;
        };
        
        function doBind(){
            
            markers = [];
            iterator = 0;
            map = null;
            
            $("#txt_filtro").bind("keyup",
                function(){
                    
                    var obj = $('#<%= dg_MisSuscripciones.ClientID %>');
                    $("tr:not(':first')",obj)
                               .show()
                               .filter(":not(\":contains('" + $(this).val() + "')\")")
                               .hide();
                }
            );
            
            setStateAdvancedSearchToggleButton();
            
            var busqueda = $('#<%= txt_busqueda.ClientID  %>');
            
            busqueda.change(function () { $("#t_razonsoc, #t_rubro, #t_desc, #t_nropub").val(""); });
            
            $("#t_razonsoc, #t_rubro, #t_desc, #t_nropub").change(function(){
               var texto = "";
               
               var r = $("#t_razonsoc").val();
               if(r != "")
               {
                    if (texto != "")
                        texto += " ";    
                    texto += "razon:" + r;
               }
                
               var ru = $("#t_rubro").val();
               if(ru != "")
               {
                    if (texto != "")
                        texto += " ";    
                    texto += "rubro:" + ru;
               }
                
               var d = $("#t_desc").val();
               if(d != "")
               {
                    if (texto != "")
                        texto += " ";    
                    texto += "desc:" + d;
               }
               
               var n = $("#t_nropub").val();
               if(n != "")
               {
                    if (texto != "")
                        texto += " ";    
                    texto += "nro:" + n;
               }
                
               if(texto != "")
                    busqueda.val(texto);
            });
        }
        
        
        function toggleAdvancedSearch()
        {
            $("#advanced-search-content").slideToggle(setStateAdvancedSearchToggleButton);            
        }
        
        function setStateAdvancedSearchToggleButton()
        {
            if($("#advanced-search-content").is(":visible"))
                $("#advanced-search").button({ icons: {primary:'ui-icon-circlesmall-minus'},text: false });
            else
                $("#advanced-search").button({ icons: {primary:'ui-icon-circlesmall-plus'},text: false });
        }
        
    </script>

</asp:Content>
